﻿using System; 
using System.Data; 
using System.Collections.Generic; 
using System.Linq;
using Dala.Samples.DataAccessLayer;

namespace  Dala.Samples.BusinessLogicLayer
{
  [System.ComponentModel.DataObject(true)]
  public partial class ProductBLL 
  {
  
    //constructor
    public ProductBLL()
    {
    	
    }
    
    public void DeleteByProductId(Int32 _ProductId)
    {
    	Product _toDel=this.GetAllProducts().FirstOrDefault(obj => obj.ProductId == _ProductId);
    	new DalaDataSource().DeleteProduct(_toDel);
    	
    }
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
    public void DeleteProduct(Product delProduct)
    {
    	new DalaDataSource().DeleteProduct(delProduct);
    	
    }
    
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public Product GetByProductId(Int32 _ProductId)
    {
    	return this.GetAllProducts().FirstOrDefault(obj => obj.ProductId == _ProductId);
    }
    
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public List<Product> GetByProductName(String _ProductName)
      {
      	return this.GetAllProducts().FindAll(obj => obj.ProductName == _ProductName);
      }

      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public List<Product> GetByItemNumber(String _ItemNumber)
      {
      	return this.GetAllProducts().FindAll(obj => obj.ItemNumber == _ItemNumber);
      }

      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public List<Product> GetByCategoryName(String _CategoryName)
      {
      	return this.GetAllProducts().FindAll(obj => obj.CategoryName == _CategoryName);
      }

      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public List<Product> GetByPrice(Decimal _Price)
      {
      	return this.GetAllProducts().FindAll(obj => obj.Price == _Price);
      }

      
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
      public int CreateNewProduct(Product newProduct)
      {
      	new DalaDataSource().GetAllProducts().Add(newProduct);
      	Product oldProduct = this.GetAllProducts().FirstOrDefault(obj => obj.ProductId == newProduct.ProductId);
      	return oldProduct.ProductId;
      }
      
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public List<Product> GetAllProducts()
      {	
          return new DalaDataSource().GetAllProducts();
      
      }
      
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
      public void UpdateProduct(Product updatedProduct)
      {
      	Product oldProduct = this.GetAllProducts().FirstOrDefault(obj => obj.ProductId == updatedProduct.ProductId);
      	if(oldProduct!=null)
      	{
      		oldProduct.ProductId=updatedProduct.ProductId;
      oldProduct.ProductName=updatedProduct.ProductName;
      oldProduct.ItemNumber=updatedProduct.ItemNumber;
      oldProduct.CategoryName=updatedProduct.CategoryName;
      oldProduct.Price=updatedProduct.Price;
      	}
      	
      }
    }//end Product class
    [System.ComponentModel.DataObject(true)]
    public partial class LocationBLL 
    {
    
      //constructor
      public LocationBLL()
      {
      	
      }
      
      public void DeleteByLocationId(Int32 _LocationId)
      {
      	Location _toDel=this.GetAllLocations().FirstOrDefault(obj => obj.LocationId == _LocationId);
      	new DalaDataSource().DeleteLocation(_toDel);
      	
      }
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
      public void DeleteLocation(Location delLocation)
      {
      	new DalaDataSource().DeleteLocation(delLocation);
      	
      }
      
      [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
      public Location GetByLocationId(Int32 _LocationId)
      {
      	return this.GetAllLocations().FirstOrDefault(obj => obj.LocationId == _LocationId);
      }
      
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByName(String _Name)
        {
        	return this.GetAllLocations().FindAll(obj => obj.Name == _Name);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByAddress(String _Address)
        {
        	return this.GetAllLocations().FindAll(obj => obj.Address == _Address);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByCity(String _City)
        {
        	return this.GetAllLocations().FindAll(obj => obj.City == _City);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByState(String _State)
        {
        	return this.GetAllLocations().FindAll(obj => obj.State == _State);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByZipCode(String _ZipCode)
        {
        	return this.GetAllLocations().FindAll(obj => obj.ZipCode == _ZipCode);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByLatitude(String _Latitude)
        {
        	return this.GetAllLocations().FindAll(obj => obj.Latitude == _Latitude);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetByLongitude(String _Longitude)
        {
        	return this.GetAllLocations().FindAll(obj => obj.Longitude == _Longitude);
        }

        
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public int CreateNewLocation(Location newLocation)
        {
        	new DalaDataSource().GetAllLocations().Add(newLocation);
        	Location oldLocation = this.GetAllLocations().FirstOrDefault(obj => obj.LocationId == newLocation.LocationId);
        	return oldLocation.LocationId;
        }
        
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<Location> GetAllLocations()
        {	
            return new DalaDataSource().GetAllLocations();
        
        }
        
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public void UpdateLocation(Location updatedLocation)
        {
        	Location oldLocation = this.GetAllLocations().FirstOrDefault(obj => obj.LocationId == updatedLocation.LocationId);
        	if(oldLocation!=null)
        	{
        		oldLocation.LocationId=updatedLocation.LocationId;
        oldLocation.Name=updatedLocation.Name;
        oldLocation.Address=updatedLocation.Address;
        oldLocation.City=updatedLocation.City;
        oldLocation.State=updatedLocation.State;
        oldLocation.ZipCode=updatedLocation.ZipCode;
        oldLocation.Latitude=updatedLocation.Latitude;
        oldLocation.Longitude=updatedLocation.Longitude;
        	}
        	
        }
      }//end Location class
  }
  
